﻿/****************************************************************************
 * 2018.8 DESKTOP-QE44MRN
 ****************************************************************************/

using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using QFramework;
using Model;

namespace QFramework.Example
{
    public class UIMainPanelData : UIPanelData
    {
        // TODO: Query Mgr's Data
    }

    public partial class UIMainPanel : UIPanel
    {
        private void Update()
        {
            if (Input.GetKey(KeyCode.G))
            {
                mTodoList.todoList[2].Headline = "已经改了";
            }
        }
        public TodoList mTodoList;
        
        protected override void InitUI(IUIData uiData = null)
        {
            mData = uiData as UIMainPanelData ?? new UIMainPanelData();
            //please add init code here
            mTodoList = new TodoList()
            {
                todoList=new List<TodoItem>()
                {  
                new TodoItem{Id=0,Headline="假数据0",Finished=false },
                 new TodoItem{Id=1,Headline="假数据1",Finished=false }            
        }
            };

            foreach (TodoItem item in mTodoList.todoList)
            {
                UITodoItem temp = Instantiate(TodoListItem, TodoListContent.transform);

                // temp.gameObject.GetComponent<Text>().text= todoItem.headline;
                temp.todo = item;
                temp.Init();
            }

        }

        protected override void ProcessMsg(int eventId, QMsg msg)
        {
            throw new System.NotImplementedException();
        }

        public void OnAddCilck(TodoItem todoItem)
        {
           

            mTodoList.AddTodoItem(todoItem);
            UITodoItem temp = Instantiate(TodoListItem, TodoListContent.transform);

            // temp.gameObject.GetComponent<Text>().text= todoItem.headline;
            temp.todo = todoItem;
            temp.Init();
            Debug.Log("一共有" + mTodoList.todoList.Count);
        }

        protected override void RegisterUIEvent()
        {
            Btn.onClick.AddListener(() =>
            {
                TodoItem todoItem = new TodoItem { Headline = "标题" + mTodoList.todoList.Count };

                OnAddCilck(todoItem);

            });
        }

        protected override void OnShow()
        {
            base.OnShow();
        }

        protected override void OnHide()
        {
            base.OnHide();
        }

        protected override void OnClose()
        {
            base.OnClose();
        }

        void ShowLog(string content)
        {
            Debug.Log("[ UIMainPanel:]" + content);
        }
    }
}